<?php

namespace app\content\controller;

use library\Controller;


/** 文章
 * Created by PhpStorm.
 * User: ycp
 * Date: 2019/11/18
 * Time: 21:07
 */

class Article extends Controller
{
    protected $table = 'lite_article';

    //文章首页
    public function index()
    {
        $this->title = '文章管理';
        $where = ['is_deleted' => '0'];
        $this->_query($this->table)->like('name')->where($where)->page();
    }

    //添加文章
    public function add()
    {
        $this->title = '添加文章';
        $this->isAddMode = '1';
        $cateData = db("lite_article_cate")->where(['is_deleted' => 0])->select();
        $this->cateData = $cateData;
        $this->applyCsrfToken();
        return $this->_form($this->table, 'form');
    }

    public function edit()
    {
        $this->title = '编辑文章';
        $cateData = db("lite_article_cate")->where(['is_deleted' => 0])->select();
        $this->cateData = $cateData;
        $this->isAddMode = '0';
        $this->applyCsrfToken();
        return $this->_form($this->table, 'form');
    }

    /**
     * 表单结果处理
     * @param boolean $result
     */
    protected function _form_result($result)
    {
        if ($result && $this->request->isPost()) {
            $this->success('文章编辑成功！', 'javascript:history.back()');
        }
    }

    public function del()
    {
        $this->applyCsrfToken();
        $this->_delete($this->table);
    }


    public function _form_filter(&$data)
    {
        if ($this->request->isGet()) {
        } elseif ($this->request->isPost()) {
            $data['create_at'] = date('Y-m-d H:i:s');
        }
    }
}